# quiz_master.py
import question_bank

def display_question(question):
    """显示题目"""
    print(f"题目ID: {question['id']}")
    print(f"题目: {question['question']}")
    print()

def run_question(question):
    """运行题目对应的代码块"""
    question['execute']()

def main():
    while True:
        print("1. 显示所有题目")
        print("2. 运行选中的题目")
        print("3. 添加新题目")
        print("4. 退出")
        choice = input("请选择一个选项: ")

        if choice == "1":
            for q in question_bank.question_bank:
                display_question(q)
        elif choice == "2":
            question_id = int(input("请输入题目ID: "))
            found = False
            for q in question_bank.question_bank:
                if q["id"] == question_id:
                    display_question(q)
                    run_question(q)
                    found = True
                    break
            if not found:
                print("未找到题目。")
        elif choice == "3":
            question_text = input("请输入新题目: ")
            question_bank.add_question(question_text, lambda: None)  # 这里需要实际的函数
            print("题目添加成功。")
        elif choice == "4":
            print("退出程序。")
            break
        else:
            print("无效选项，请重新选择。")

if __name__ == "__main__":
    main()